package games.platformer.behaviors;

import vooga.entities.Entity;
import vooga.behaviors.AbstractBehavior;



/**
 * Remove After Time behavior
 * used to make platforms that go away a certain amount of time after you first step on them
 * 
 * created 12-10
 * @author Ben Shelton
 * @author Congyi Wu
 */
public class RemoveAfterTime extends AbstractBehavior
{
	
	private int myTime; // in frames
	
	private games.platformer.Level myLevel;
	
	private Entity myBlock;
	
	private boolean myBreakEnabled;
	
    public RemoveAfterTime(int time, games.platformer.Level level, Entity block)
    {
    	myTime = time;
    	myLevel = level;
    	myBlock = block;
    	myBreakEnabled = false;
    }
    
    /**
     * 
     */
    public void step (Entity target)
    {
    	if(target.intersects(myBlock))
    	{
    		myBreakEnabled = true;
    	}
    	
    	if(myBreakEnabled == true)
    	{
    		myTime--;
    	}
    	
    	if(myTime == 0)
    	{
    		myLevel.removeEntity(myBlock.getClass().cast(myBlock));
    	}
    }
}
